package com.saturn.action.sldb.emergency;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.saturn.app.utils.BeanUtils;
import com.saturn.app.web.IAction;
import com.saturn.app.web.IView;
import com.saturn.app.web.view.JspErrorView;
import com.saturn.app.web.view.JspView;
import com.saturn.sldb.Emergency;
import com.saturn.sldb.TempSub;

public class UpdateEmergencyAction implements IAction{
	@Override
	public IView execute(HttpServletRequest request,
			HttpServletResponse response) {
		Emergency vo = BeanUtils.getBean(request, Emergency.class);
		
		String[] c_inputType = request.getParameterValues("c_inputType");
		String[] c_name = request.getParameterValues("c_name"); // 姓名
		String[] c_sex = request.getParameterValues("c_sex"); // 性别
		String[] c_relation = request.getParameterValues("c_relation"); // 与户主关系
		String[] c_identify = request.getParameterValues("c_identify"); // 身份证号
		String[] c_contact = request.getParameterValues("c_contact"); // 联系电话
		
		List<TempSub> list = new ArrayList<TempSub>();
		
		for(int i=0; i<c_name.length; i++){
			if (!"".equals(c_name[i]) || !"".equals(c_sex[i])
					|| !"".equals(c_relation[i])
					|| !"".equals(c_identify[i])
					|| !"".equals(c_contact[i])
					|| !"".equals(c_inputType[i])) {
				TempSub sub = new TempSub(null, c_identify[i],
						c_name[i], c_sex[i], c_contact[i],
						vo.getCreateTime(), vo.getCreater(),
						vo.getCreaterName(), vo.getCreaterDepartment(),
						vo.getState(), vo.getInputType(), null,
						c_relation[i], vo.getName());
				list.add(sub);
			}
		}

		if (Emergency.edit(vo, list) == 1) {
			return new JspView("/app/sldb/emergency/apply/show.jsp");
		} else {
			return new JspErrorView("更新信息失败");
		}
	}
	@Override
	public String requestMapping() {
		return "/app/sldb/emergency/apply/updateEmergency.action";
	}
}
